package com.pro.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pro.dao.MemberMapper;
import com.pro.domain.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    /*注册*/
    @Override
    public void createMember(String username, String password, String nickname){
        Member member = new Member();
        try {
            member.setUsername(username);
            member.setNickname(nickname);
            member.setPassword(password);
            memberMapper.insert(member);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /*登录*/
    @Override
    public Map checkLogin(String username, String password)   {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<Member>();
        Map map = new HashMap();
        queryWrapper.eq("username",username);
        Member member = memberMapper.selectOne(queryWrapper);
        if(member==null){
            map.put("code","membernull");
            return map;
        }
        if(!password.equals(member.getPassword())){
            map.put("code","pwderr");
            return map;
        }
        map.put("token",member);
        map.put("code","right");
        return map;
    }
}
